package si.banst.tecajnice.entitete;

import static javax.persistence.EnumType.STRING;
import static javax.persistence.TemporalType.TIMESTAMP;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.Column;

@Entity
@NamedQueries({
		@NamedQuery(name = "vrniVsePonderje", query = "SELECT p FROM Ponder p"),
		@NamedQuery(name = "vrniPonderjeZaVrstoTecejnice", query = "SELECT p FROM Ponder p WHERE p.id.sifraVrsteTecajnice = :sifraVrsteTecajnice"),
		@NamedQuery(name = "vrniVseNeaktivnePonderje", query = "SELECT p FROM Ponder p WHERE p.statusAktivnosti = si.banst.tecajnice.entitete.StatusAktivnosti.NEAKTIVEN")})
public class Ponder implements Serializable {

	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private PonderID id;

	@Temporal(TIMESTAMP)
	private Date datumCasSpremembe;

	@Column(scale = 4, precision = 24)
	private BigDecimal odmikNakupnegaTecaja;

	@Column(scale = 4, precision = 24)
	private BigDecimal odmikProdajnegaTecaja;

	private String referent;

	@Enumerated(STRING)
	private StatusAktivnosti statusAktivnosti;

	@ManyToOne
	private VrstaTecajnice vrstaTecajnice;

	@ManyToOne
	private Valuta valuta;

	public Ponder() {
		super();
	}

	public PonderID getId() {
		return id;
	}

	public void setId(PonderID id) {
		this.id = id;
	}

	public Date getDatumCasSpremembe() {
		return datumCasSpremembe;
	}

	public void setDatumCasSpremembe(Date datumCasSpremembe) {
		this.datumCasSpremembe = datumCasSpremembe;
	}

	public BigDecimal getOdmikNakupnegaTecaja() {
		return odmikNakupnegaTecaja;
	}

	public void setOdmikNakupnegaTecaja(BigDecimal odmikNakupnegaTecaja) {
		this.odmikNakupnegaTecaja = odmikNakupnegaTecaja;
	}

	public BigDecimal getOdmikProdajnegaTecaja() {
		return odmikProdajnegaTecaja;
	}

	public void setOdmikProdajnegaTecaja(BigDecimal odmikProdajnegaTecaja) {
		this.odmikProdajnegaTecaja = odmikProdajnegaTecaja;
	}

	public String getReferent() {
		return referent;
	}

	public void setReferent(String referent) {
		this.referent = referent;
	}

	public StatusAktivnosti getStatusAktivnosti() {
		return statusAktivnosti;
	}

	public void setStatusAktivnosti(StatusAktivnosti statusAktivnosti) {
		this.statusAktivnosti = statusAktivnosti;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Ponder))
			return false;
		Ponder other = (Ponder) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public VrstaTecajnice getVrstaTecajnice() {
		return vrstaTecajnice;
	}

	public void setVrstaTecajnice(VrstaTecajnice vrstaTecajnice) {
		this.vrstaTecajnice = vrstaTecajnice;
	}

	public Valuta getValuta() {
		return valuta;
	}

	public void setValuta(Valuta valuta) {
		this.valuta = valuta;
	}

	@Override
	public String toString() {
		return "Ponder [id=" + id + ", datumCasSpremembe=" + datumCasSpremembe
				+ ", odmikNakupnegaTecaja=" + odmikNakupnegaTecaja
				+ ", odmikProdajnegaTecaja=" + odmikProdajnegaTecaja
				+ ", referent=" + referent + ", statusAktivnosti="
				+ statusAktivnosti + ", vrstaTecajnice=" + vrstaTecajnice
				+ ", valuta=" + valuta + "]";
	}

}